import {reactive} from "vue";
import http from "../utils/http";

const login = reactive({
    loginForm: {
        account: "19359369523",
        pass: "123",                       // 密码
        checkPass: "123",                  // 确认密码
        code: "1234",                       // 验证码
    },
    remember: false,                // 记住密码
    is_register: true,                 // 是登陆还是注册
    code_msg: "获取验证码",                      // 验证码提示信息
    code_time: 60,                  // 验证码倒计时时间
    timer: null,                     // 验证码倒计时
    formObj: null,                   // 表单对象
    loginFormVisible: false,         // 忘记密码表单是否可见


    //     发送验证码
    sendCode() {
        return http.get(`users/sms/${this.loginForm.account}`)
    },

    // 查看是否有此手机号
    checkPhone() {
        return http.get(`users/mobile/${this.loginForm.account}`)
    },

    // 注册
    registerUser() {
        return http.post(`users/register/`, {
            mobile: this.loginForm.account,
            password: this.loginForm.pass,
            re_password: this.loginForm.checkPass,
            sms_code: this.loginForm.code,
        })
    },


    // 登陆
    loginUser() {
        return http.post(`users/login/`, {
            username: this.loginForm.account,
            password: this.loginForm.pass,
        })
    },

    // 忘记密码
    forgetPassword() {
        return http.put(`users/forget/${this.loginForm.account}/`, {
            mobile: this.loginForm.account,
            password: this.loginForm.pass,
            re_password: this.loginForm.checkPass,
            sms_code: this.loginForm.code,
        })
    },

})

export default login